package net.seehope.foodie.config;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import net.seehope.foodie.controller.Filter.TimeFilter;
import net.seehope.foodie.controller.Intercepter.AllowOriginIntercepter;
import net.seehope.foodie.controller.Intercepter.TimeIntercepter;


//在容器中配置web组件，需要继承WebMvcConfigurer
@Configuration
public class WebConfig implements WebMvcConfigurer{
	
	@Autowired
	private TimeIntercepter timeIntercepter;
	
	@Autowired
	private AllowOriginIntercepter allowOriginIntercepter1;
	
	//配置拦截器
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		System.out.println("hello");
		registry.addInterceptor(allowOriginIntercepter1);
		registry.addInterceptor(timeIntercepter);
	}


	
	//需要向spring容器中提供一个FilterRegistrationBean类的实现，专门用于注册Filter，有一个Filter就需要注册一个
	
	//由于反转，tomcat也注入到spring里面了，相关的web配置也得注入
//	@Bean
//	public FilterRegistrationBean timeFilter() {
//		FilterRegistrationBean bean = new FilterRegistrationBean();
//		TimeFilter timeFilter = new TimeFilter();
//		bean.setFilter(timeFilter);
//		
//		//设置拦截路径
//		List<String> urls = new ArrayList();
//		
//		urls.add("/index/*");
//		bean.setUrlPatterns(urls);
//		return bean;
//	}

	//在web配置文件中注册，Intercepter默认是拦截所有请求
	

	 
	

	
}
